/**
 * DefaultTrackableImpl.java
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2013-8-9
 */
package com.pshare.session.impl;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

import com.pshare.session.Trackable;


/**
 * 默认的会话追踪接口实现类
 */
public class DefaultTrackableImpl implements Trackable {

    private volatile String trackId;

    public DefaultTrackableImpl(String trackId) {
        super();
        this.trackId = trackId;
    }

    public DefaultTrackableImpl(Object object, String attrName) {
        super();
        if (object == null)
            throw new NullPointerException("object is null.");
        if (StringUtils.isBlank(attrName))
            throw new IllegalArgumentException("attrName is blank.");
        try {
            trackId = BeanUtils.getProperty(object, attrName);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            trackId = null;
        }
    }

    @Override
    public String getTrackId() {
        return trackId;
    }

}
